<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
export default {
  name: "App",
  mounted() {
    // this.WX_login(); //正式服必开

  },
  methods: {
    login() {
      let address = "";
      if (window.location.href.split("#/")[1].indexOf("mine") == -1) {
        address = window.location.href.split("#/")[1];
      }
      let url = encodeURIComponent("http://www.tissys.com/mobile#/"+address);// 正式服
      // let url = encodeURIComponent("http://tennis.laigl.com/mobile#/" + address);// 测试服 
      // "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
      window.location.href =
        "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb4cd52cc33df2328&redirect_uri=" +
        url +
        "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
    },
    WX_login() {
      let address = window.location.href.split("#/")[1];
      if (window.location.search) {
        let code = window.location.search.substring(1).split("&");
        for (let i = 0; i < code.length; i++) {
          let need = code[i].split("=");
          if (need[0] == "code" && need[1]) {
            var params = new URLSearchParams();
            params.append("code", need[1]);
            this.$axios
              .post("/mobile/BassController/is_bound", params)
              .then(res => {
                // console.log(res)
                window.sessionStorage.setItem("res", res);
                window.sessionStorage.setItem("code", res.data.code);
                if (res.data.code == 2000) {
                  window.sessionStorage.setItem("token", res.data.data.token);
                  window.localStorage.setItem("openid", res.data.data.openid);
                }
                if (res.data.code == 2002) {
                   window.localStorage.setItem("openid", res.data.data.openid);
                }
                if (res.data.code == 2003 || res.data.code == 2001) {
                  this.login();
                }
              });
            return;
          } else {
            this.login();
          }
        }
      } else if (!window.sessionStorage.getItem("token")) {
        this.login();
      }
    }
  }
};
</script>
<style>
@import "http://at.alicdn.com/t/font_999173_wt5tew7hg0c.css";
@import "http://at.alicdn.com/t/font_1910038_usxypdz7g6r.css";
html {
  font-size: calc(75px * 2 / 3);
  background-color: #f6f6f6;
}

* {
  padding: 0;
  margin: 0;
}

#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  font-size: 0.28rem;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.title > .van-cell {
  background-color: #c0e6d1 !important;
}
</style>
